﻿using CommunityToolkit.Mvvm.ComponentModel;
using GameView.Comment;
using GameView.Models;
using GameView.Services.Comment;
using GameView.Services.Dtos.RechargesDto;

namespace GameView.Services
{
    public partial class RechargeService : ObservableObject
    {
        [ObservableProperty]
        private bool _isLoading;

        public async Task<ApiResponse<RechargeRecord>> AddNewAsync(RechargeAddDto id)
        {
            IsLoading = true;
            var res = await $"{APIHelper.Recharge}".AddNewAsync<RechargeAddDto, RechargeRecord>(id);
            IsLoading = false;
            return res;
        }

        public async Task<ApiResponse<List<RechargeRecord>>> GetTop(int count, bool isGameUser)
        {
            var res = await $"{APIHelper.Recharge}/top/{count}/{isGameUser}/{StaticValues.LoginInfo.PersonInfo.Account}".GetAsync<List<RechargeRecord>, object>();
            IsLoading = false;
            return res;
        }

        public async Task<ApiResponse<PagedList<RechargeRecord>>> GetPageAsync(RechargeQueryDto id)
        {
            if (id.EndTime.IsNullOrEmpty())
                id.EndTimeDT = DateTime.Now.ToStringMax();
            if (id.StartTime.IsNullOrEmpty())
                id.StartTimeDT = DateTime.Now.AddHours(-24).ToStringMin();
            IsLoading = true;
            var rr = JSON.Serialize(id);
            var res = await $"{APIHelper.Recharge}/by-page".PostAsync<PagedList<RechargeRecord>, RechargeQueryDto>(id);
            IsLoading = false;
            return res;
        }

        public async Task<ApiResponse<List<long>>> GetSTAsync(RechargeQueryDto id)
        {
            if (id.EndTime.IsNullOrEmpty())
                id.EndTimeDT = DateTime.Now.ToStringMax();
            if (id.StartTime.IsNullOrEmpty())
                id.StartTimeDT = DateTime.Now.AddHours(-24).ToStringMin();
            IsLoading = true;
            var rr = JSON.Serialize(id);
            var res = await $"{APIHelper.Recharge}/by-st".PostAsync<List<long>, RechargeQueryDto>(id);
            IsLoading = false;
            return res;
        }
    }
}